package cn.stylefeng.guns.modular.business.controller;

import cn.stylefeng.guns.modular.business.entity.AttendanceRecordRequest;
import cn.stylefeng.guns.modular.business.service.AttendanceRecordService;
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.resource.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@ApiResource(name = "考勤管理")
public class AttendanceController {

    @Resource
    private AttendanceRecordService attendanceRecordService;

    /**
     * 分页查询考勤
     */
    @GetResource(name = "分页查询考勤", path = "/attendance/page")
    public ResponseData page(AttendanceRecordRequest attendanceRecordRequest) {
        return new SuccessResponseData(attendanceRecordService.findPage(attendanceRecordRequest));
    }

    /**
     * 打卡接口
     */
    @PostResource(name = "打卡", path = "/attendance/attend")
    public ResponseData attend(AttendanceRecordRequest attendanceRecordRequest) {
        LoginUser loginUser = LoginContext.me().getLoginUser();
        attendanceRecordService.attend(loginUser);
        return new SuccessResponseData();
    }
}
